﻿#include "addvip_dialog.h"
#include "ui_addvip_dialog.h"
#include "vip_dialog.h"
#include <QSqlQuery>
#include <QMessageBox>

addvip_dialog::addvip_dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::addvip_dialog)
{
    ui->setupUi(this);
    //默认聚焦设置
    ui->vipnameEdit->setFocus();
}

addvip_dialog::~addvip_dialog()
{
    delete ui;
}

//添加按钮
void addvip_dialog::on_addBtn_clicked()
{
    QString id = ui->editId->text();
    QString name = ui->vipnameEdit->text();
    QString cell = ui->vipcellEdit->text();
    QString level = ui->comboBox->currentText();

    //定义FLAG常量 标识后台管理员和前台收银员添加的区别 1为前台的操作表示
    if(addvip_dialog::FLAG == "1"){
        QSqlQuery query;
        QString sql = "insert into vip(v_id,v_name,v_cell,v_level,v_allconsum) "
                      "values('" +id+ "','" +name+ "','" +cell+ "','" +level+ "','0');";
        if(query.exec(sql)){
            QMessageBox::about(NULL, "提示", "添加成功");
            this->close();
        }else{
            QMessageBox::about(NULL, "提示", "添加失败");
        }
    }else{
        //信号
        emit addVip(id, name, cell, level);
        this->close();
    }
}

